package com.medical.goods.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.medical.goods.entity.TypeEntity;
import com.medical.goods.service.TypeService;
import com.medical.common.utils.PageUtils;
import com.medical.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2021-08-13 20:42:37
 */
@RestController
@RequestMapping("goods/type")
public class TypeController {
    @Autowired
    private TypeService typeService;

    //查询商品信息下的分类
    @RequestMapping("/typelist")
    public List<TypeEntity> typelist(){
        return typeService.list();
    }

    //商品分类列表
    @RequestMapping("/tlist")
    public List<TypeEntity> tlist(@RequestBody TypeEntity typeEntity){
       return typeService.tlist(typeEntity);
    }


    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params,@RequestBody TypeEntity typeEntity){
        PageUtils page = typeService.queryPage(params,typeEntity);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{tid}")
    public R info(@PathVariable("tid") Integer tid){
		TypeEntity type = typeService.getById(tid);

        return R.ok().put("type", type);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody TypeEntity type){
		typeService.save(type);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody TypeEntity type){
		typeService.updateById(type);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{tid}")
    public R delete(@PathVariable("tid")Integer tid){
		typeService.removeById(tid);

        return R.ok();
    }

}
